import { Map } from "immutable"

import {
    CHANGE_CURRENT_SONG,
    CHANGE_PLAY_LIST,
    CHANGE_CURRENT_SONG_INDEX,
    CHANGE_SEQUENCE,
    CHANGE_LYRIC_LIST,
    CHANGE_CURRENT_LYRIC_INDEX,
    CHANGE_SIMI_SONGS,
    CHANGE_SIMI_PLAYLIST,

    CHANGE_SONG_DETAIL,
    CHANGE_PLAY_LYRIC_LIST
} from "./constants"


const defaultState = Map({
    playList: [],//播放列表数据
    currentSongIndex: 0,//当前歌曲在 播放列表中的 索引值
    currentSong: {},//当前正在播放的歌曲对象
    sequence: 0, // 0 顺序  1 随机 2 单曲循环
    lyricList: [],//当前播放的歌曲的歌词数组
    currentLyricIndex: 0,// 正在播放的歌词对象(歌词数组中的)的索引值

    simiPlayList: [],// simiPlaylist
    simiSongs: [],

    playerSongDetail: {},//查看歌曲播放页面 歌曲详情
    playerLyricList: [],//查看歌曲播放页面 歌曲的歌词
})

function reducer (state = defaultState, action) {
    switch (action.type) {
        case CHANGE_CURRENT_SONG:
            // return {...state, currentSong: action.songs}
            return state.set("currentSong", action.currentSong)

        case CHANGE_PLAY_LIST:
            return state.set("playList", action.playList)

        case CHANGE_CURRENT_SONG_INDEX:
            return state.set("currentSongIndex", action.index)

        case CHANGE_SEQUENCE:
            return state.set("sequence", action.sequence)

        case CHANGE_LYRIC_LIST:
            return state.set("lyricList", action.lyricList)

        case CHANGE_CURRENT_LYRIC_INDEX:
            return state.set("currentLyricIndex", action.index)

        case CHANGE_SIMI_SONGS:
            return state.set("simiSongs", action.simiSongs)

        case CHANGE_SIMI_PLAYLIST:
            return state.set("simiPlayList", action.simiPlaylist);

        case CHANGE_SONG_DETAIL:
            return state.set("playerSongDetail", action.songDetail);

        case CHANGE_PLAY_LYRIC_LIST:
            return state.set("playerLyricList", action.lyricList)

        default:
            return state;
    }
}

export default reducer